var glNoteServices = angular.module('glNoteServices', ['ngResource','jlareau.pnotify']);
glNoteServices.factory('SignInService', ['myConfig','$resource', function(myConfig,$resource){
	return $resource(myConfig.signInUrl,null,{
		'signIn':{method:'post'}
	});
}])
.factory('SignUpService', ['myConfig','$resource', function(myConfig,$resource){
	return $resource(myConfig.signUpUrl,null,{
		'signUp':{method:'post'}
	});
}])
.factory('CheckUserService', ['myConfig','$resource', function(myConfig,$resource){
	return $resource(myConfig.checkUserUrl);
}])
.factory('ResetPwdService', ['myConfig','$resource', function(myConfig,$resource){
	return $resource(myConfig.resetPwdUrl,null,{
		'resetPwd':{method:'post'}
	});
}])
.factory('WebStorageService', [function(){
	return {
		saveLoginInfo:function(loginInfo){
			if(typeof(Storage) !== "undefined") {
                // Code for localStorage/sessionStorage.
                sessionStorage.LoginInfo = JSON.stringify(loginInfo);
            } else {
                // Sorry! No Web Storage support..
                console.log("Error: session storeage not supported");
            }
		},
		getLoginInfo:function(){
            if(sessionStorage.LoginInfo){
                var loginInfo = JSON.parse(sessionStorage.LoginInfo);
                return loginInfo;
            }else{
                return sessionStorage.LoginInfo;
            }
            
		},
        saveForRemMe: function(email, checked){
            if(typeof(Storage) !== "undefined") {
                // Code for localStorage/sessionStorage.
                localStorage.email = email;
                localStorage.checked = checked;
            } else {
                // Sorry! No Web Storage support..
                console.log("Error: session storeage not supported");
            }
        },
        getRemMeInfo: function(){
            var result = {};
            result.email = localStorage.email;
            result.checked = (localStorage.checked == 'true');
            return result;
        }
	};
}])
.factory('ShowStatus', ['myConfig','notificationService',function(myConfig,notificationService){
	var name;
	return {
		show: function(resp, succCb, failCb){
            if (resp) {
                if (resp.status == myConfig.success) {
                    notificationService.notifyWithDefaults({
                        type: 'success',
                        text: resp.desc,
                        delay: 3000
                    });
                    if(succCb)
                    	succCb(resp);
                } else {
                    notificationService.notifyWithDefaults({
                        text: resp.desc,
                        type: 'error',
                        delay: 10000
                    });
                    if(failCb)
                    	failCb(resp);
                }
            } else {
                notificationService.notifyWithDefaults({
                    type: 'error',
                    text: myConfig.connect_error,
                    delay: 3000
                });
                if(failCb)
                	failCb(resp);
            }
		}
	};
}]);